<template>
  <div class="all-job-resume">
    <div class="all-job-resume-head">
      <el-col :span="23">
        <span class="all-job-resume-line"></span>
        项目经历
        <span class="all-job-resume-sub-text">必填</span>
      </el-col>
      <el-col :span="1" v-if="data.length < 11">
        <i class="el-icon-circle-plus plus-add" @click="addContent"></i>
      </el-col>
    </div>

    <project-experience-list
      :form="form"
      v-for="(item,index) in data"
      :key="index"
      :data="item"
      @on-pitch="cancel"
    ></project-experience-list>

    <div class="edit-content" v-if="form.sta == 3 && form.editSta == -1">
      <div class="all-job-resume" style="padding:24px 0 0 0; background:#f7fdff;">
        <el-form label-width="100px" label-position="right">
          <el-row>
            <el-col :span="12">
              <el-form-item label="项目名称">
                <el-input class="theme-input all-input" v-model="params.projectName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="项目时间">
                <el-date-picker
                  :editable="false"
                  class="resume-datepicker"
                  type="monthrange"
                  value-format="yyyy-MM"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  v-model="params.time"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="工作内容">
            <el-input type="textarea" v-model="params.projectContent"></el-input>
          </el-form-item>
          <el-form-item class="form-button-right">
            <el-button class="ghost-button" @click="cancel">取消</el-button>
            <el-button class="submit-button" @click="doSubmit">确认</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import projectExperienceList from './list/project-experience-list'
import { constants } from 'crypto'
export default {
  props: ['form', 'data'],
  data() {
    return {
      params: {
        id: '',
        projectName: '',
        time: [],
        projectContent: ''
      },
      pickerOptions: {
        shortcuts: [
          {
            text: '今年至今',
            onClick(picker) {
              const end = new Date()
              const start = new Date(new Date().getFullYear(), 0)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      }
    }
  },
  methods: {
    check() {
      if (
        this.params.projectName == '' ||
        this.params.time == '' ||
        this.params.projectContent == ''
      ) {
        _g.message('数据不能为空', 'warning')
        return false
      }
      return true
    },
    addContent() {
      //点击添加按钮
      this.form.sta = 3
      this.form.editSta = -1
    },
    cancel() {
      //点击添加按钮
      this.$emit('on-pitch', true)
      this.form.sta = -1
      this.form.editSta = -1
    },
    doSubmit() {
      //点击确定

      if (!this.check()) return false
      let params = {
        id: this.params.id,
        projectName: this.params.projectName,
        projectStartTime: this.params.time[0],
        projectEndTime: this.params.time[1],
        projectContent: _g.getTextAreaTo(this.params.projectContent)
      }
      _g.apiPost('/talent/updateProjectExp.do', params).then(res => {
        _g.toMessage(res)
        this.cancel()
        this.emptyData()
      })
    },
    emptyData() {
      this.params.id = ''
      this.params.projectName = ''
      this.params.projectContent = ''
      this.params.time = []
    }
  },

  components: {
    projectExperienceList
  }
}
</script>

<style lang="scss" scoped>
</style>
